<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8" />
    <title>{eyou:global name='web_name' /}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <link href="{eyou:global name='web_cmspath'/}/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    
   <!-- 新样式 2020-12-8 -->
   {eyou:static file="users/skin/css/element/index.css" /}
   {eyou:static file="users/skin/userfont/iconfont.css" /}
   {eyou:static file="users/skin/css/e-user.css" /}
   {eyou:include file="users/skin/css/diy_css.htm"/}

    {eyou:static file="/public/static/common/js/jquery.min.js"/}
    {eyou:static file="users/skin/js/vendor.js"/}
    {eyou:static file="/public/plugins/layer-v3.1.0/layer.js"/}
    {eyou:static file="/public/static/common/js/tag_global.js"/}
</head>

<body>
  <!--头部--->
   <div class="ey-header-status">
       <div class="header-status-l">
           <a href="javascript:history.go(-1);"><i class="el-icon-arrow-left"></i></a>
       </div> 
       <div class="header-status-m" title="订单状态">订单详情</div> 
       <div class="header-status-r"> </div>
   </div><!--头部 end--->    
   <div class="h50"></div>  
   
   <div class="ey-container order-details">
        {eyou:sporder id="field"}
       <div class="order-title">
           <div class="order-title-t">{$field.order_status_name}</div>
           {eyou:if condition="empty($field.pay_time) && 0 == $field.order_status"}
           <div class="order-title-b">请在<em class="pay-time-tip"></em>前完成付款，逾期订单将关闭。</div>
           <script type="text/javascript">
              /*
              时间倒计时插件
              TimeDown.js
              */
              TimeDown({$field.paymentExpire|default=0});
              function TimeDown(totalSeconds) {
                  //取模（余数）
                  var modulo = totalSeconds % (60 * 60 * 24);
                  //小时数
                  var hours = Math.floor(modulo / (60 * 60));
                  modulo = modulo % (60 * 60);
                  //分钟
                  var minutes = Math.floor(modulo / 60);
                  //输出到页面
                  $('.pay-time-tip').html(hours + "小时" + minutes + "分");
                  // 剩余秒数
                  totalSeconds--;
                  if (totalSeconds < 0) {
                      totalSeconds = 0;
                  }
                  //延迟一秒执行自己
                  setTimeout(function () {
                      TimeDown(totalSeconds);
                  }, 1000)
              }
           </script>
           {/eyou:if}
       </div>
       <div class="order-title-wrap">
           <span>订单信息</span>
       </div>
       <div class="item-list">
           <div class="item">
               <div class="item-l">下单日期：{$field.add_time|MyDate='Y.m.d H:i:s',###}</div> 
               <div class="item-m"></div> 
               <div class="item-r"></div>
           </div>
           <div class="item">
               <div class="item-l">订单编号：{$field.order_code}</div> 
               <div class="item-m"></div> 
               <div class="item-r"></div>
           </div>
           <div class="item">
               <div class="item-l"><i class="iconfont icon-shouhuodizhi"></i></div> 
               <div class="item-m flex flex-wrap align-c">
                   <span>{$field.consignee} {$field.mobile}</span>
                   <span>{$field.ConsigneeInfo}</span>
               </div> 
               <div class="item-r"></div>
           </div>
       </div>
       <!--商品-->
       <div class="goods-buy">
           <div class="order-title-wrap bor-b mb5">
               <span>购物清单</span>
           </div>
           {eyou:spordergoods id="field2"}
           <div class="goods-item">
               <div class="goods-item-l">
                   <div class="img"><a href="{$field2.arcurl}"><img src="{$field2.litpic}"></a></div>
               </div>
               <div class="goods-item-r">
                   <div class="title"><a href="{$field2.arcurl}">{$field2.product_name}&nbsp;</a></div>
                   <!-- 商品规格 -->
                   <div class="spec">
                       <!-- 商品规格 -->
                       {eyou:volist name='$field2.product_spec_list' id='spec'}
                       <span> {$spec.value}&nbsp;</span>
                       {/eyou:volist}
                   </div>
                   <!-- 商品规格 END-->
                   <div class="pice">
                       <div class="pice-l"><em>￥</em>{$field2.product_price}</div>
                       <div class="pice-r">x {$field2.num}</div>
                   </div>
               </div>
           </div>
            {/eyou:spordergoods}
       </div>
       <div class="order-title-wrap">
           <span>订单金额</span>
       </div>
       <div class="item-list">
           <div class="item">
               <div class="item-l">商品总价</div> 
               <div class="item-m"></div> 
               <div class="item-r"><span class="red">{$field.TotalAmount}元</span></div>
           </div>
           <div class="item">
               <div class="item-l">配送运费</div>
               <div class="item-m"></div>
               <div class="item-r"><span class="red">{$field.shipping_fee}元</span></div>
           </div>
           <div class="item">
               <div class="item-l">应付金额</div> 
               <div class="item-m"></div> 
               <div class="item-r"><span class="red">{$field.order_amount}元</span></div>
           </div>

           
           {eyou:if condition="$field.prom_type == 0 && $field.order_status > 1"}
           <div class="item">
               <div class="item-l">快递公司</div> 
               <div class="item-m"><span>{$field.express_name}</span></div> 
               <div class="item-r"></div>
           </div>
           <div class="item">
               <div class="item-l">物流单号</div> 
               <div class="item-m flex flex-wrap align-c">
                   <span>{$field.express_order}</span>
                   <span>
                       {eyou:if condition="'2' == $field.order_status or '3' == $field.order_status"}
                           {eyou:eq name="$is_wechat" value="1"}
                               <a href="{$field.MobileExpressUrl}">物流查询</a>
                           {eyou:else/}
                               <a href="JavaScript:void(0);" {$field.LogisticsInquiry}>（ 物流查询 ）</a>
                           {/eyou:eq}
                       {/eyou:if}
                   </span>
               </div> 
               <div class="item-r"></div>
           </div>
           {/eyou:if}        
       </div>
       {notin name='$field.order_status' value='-1,4'}
       <div class="h50"></div>
       <div class="order-footer-btn">
           {eyou:eq name='$field.order_status' value='0'}
               <a href="JavaScript:void(0);" class="item-btn" {$field.CancelOrder}>取消订单</a>   
              {eyou:eq name="is_wechat" value='2'}
                   <a href="{$field.PaymentUrl}" class="item-btn orange">
                       立即付款
                   </a>
               {eyou:else/}
                   <a href="JavaScript:void(0);" onclick="UpdatePayMethod('{$field.order_id}','{$field.order_code}');" class="item-btn orange">
                       立即付款
                   </a>
               {/eyou:eq}
           {/eyou:eq}
           {eyou:eq name="$field.order_status" value="1"}
           <a class="item-btn redd" href="javascript:void(0);" {$field.OrderRemind}>提醒发货</a>
           {/eyou:eq}
           <!-- 订单状态判断，待收货 -->
           {eyou:eq name="$field.order_status" value="2"}
               <a href="javascript:void(0)" class="item-btn redd" {$field.Confirm}>确认收货</a>
           {/eyou:eq}
           <!-- 判断交易完成后显示申请售后 -->
           {eyou:eq name='$field.order_status' value='3'}
           <a href="{:url('user/Shop/service_list', ['order_id'=>$field.order_id])}" class="item-btn redd">申请售后</a>
               {eyou:eq name="$field.is_comment" value="0"}
               <a href="{$field.AddProduct}" title="评价商品" class="item-btn orange">评价商品</a>
               {/eyou:eq}
           {/eyou:eq}
       </div>
       {/notin}

       {$field.hidden}
       {/eyou:sporder}
       
       <input type="hidden" id="unified_id">
       <input type="hidden" id="unified_number">
       <input type="hidden" id="transaction_type">
   </div> 


<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
<script type="text/javascript">
    $(function(){
        wx.miniProgram.getEnv( function(res) {
            if(res.miniprogram) {
                // 小程序
                var i = 0;
                i = setInterval('AppletsPay()', 1000);
            }
        });
    });

    // 小程序后查询
    function AppletsPay(){
        var unified_id       = $('#unified_id').val();
        var unified_number   = $('#unified_number').val();
        var transaction_type = $('#transaction_type').val();
        if (unified_id && unified_number && transaction_type) {
            $.ajax({
                url: "{eyou:url link='user/Pay/ajax_applets_pay'/}",
                data: {unified_id:unified_id, unified_number:unified_number, transaction_type:transaction_type},
                type:'post',
                dataType:'json',
                success:function(res){
                    if (1 == res.code) {
                        if (!res.data.mobile && !res.data.email) window.location.href = res.url;
                        if (res.data.mobile) SendMobile(res.data.mobile);
                        if (res.data.email) SendEmail(res.data.email);
                        window.location.href = res.url;
                    }
                }
            });    
        }
    }

    // 判断支付类型是否一致并且更新支付方式
    function UpdatePayMethod(unified_id,unified_number,transaction_type='2'){
        layer_loading_mini();
        $.ajax({
            url: "{eyou:url link='user/Pay/update_pay_method'/}",
            data: {unified_id:unified_id,unified_number:unified_number,pay_method:'WeChatInternal',transaction_type:transaction_type,order_source:2},
            type:'post',
            dataType:'json',
            success:function(res){
                layer.closeAll();
                if (0 == res.code) {
                    showErrorAlert(res.msg);
                }else{
                    if (1 == res.data.is_gourl) {
                        window.location.href = res.url;
                    }else{
                        $('#unified_id').val(unified_id);
                        $('#unified_number').val(unified_number);
                        $('#transaction_type').val(transaction_type);
                        WeChatInternal(unified_id,unified_number,transaction_type);
                    }
                }
            }
        });
    }

    // 微信内部中进行支付
    function WeChatInternal(unified_id,unified_number,transaction_type)
    {
        wx.miniProgram.getEnv( function(res) {
            if(res.miniprogram) {
                // 小程序
                wx.miniProgram.navigateTo({
                    url: '/pages/pay/pay?unified_id='+ unified_id +'&unified_number=' + unified_number + '&type=' + transaction_type
                });
            } else {
                $.ajax({
                    url: "{eyou:url link='user/Pay/wechat_pay'/}",
                    data: {unified_id:unified_id,unified_number:unified_number,transaction_type:transaction_type},
                    type:'post',
                    dataType:'json',
                    success:function(res){
                        layer.closeAll();
                        if (1 == res.code) {
                            callpay(res.msg);
                        }else{
                            showErrorAlert(res.msg);
                        }
                    }
                });
            }
        });

    }

    //调用微信JS api 支付
    function jsApiCall(data)
    {
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest',data,
            function(res){
                if(res.err_msg == "get_brand_wcpay_request:ok"){  
                    pay_deal_with();
                    // layer.msg('微信支付完成！', {time: 1000}, function(){
                    //     pay_deal_with();
                    // });
                }
                // else if(res.err_msg == "get_brand_wcpay_request:cancel"){
                //     showErrorAlert('用户取消支付！');
                // }
                // else{
                //     showErrorAlert('支付失败！');
                // }
            }
        );
    }
    
    // 微信内部支付时，先进行数据判断
    function callpay(data)
    {
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }else{
            jsApiCall(data);
        }
    }

    function pay_deal_with(){
        var unified_number   = $('#unified_number').val();
        var transaction_type = $('#transaction_type').val();
        $.ajax({
            url: "{eyou:url link='user/Pay/pay_deal_with'/}",
            data: {unified_number:unified_number,transaction_type:transaction_type},
            type:'post',
            dataType:'json',
            success:function(res){
                if (1 == res.data.status) {
                    if (!res.data.mobile && !res.data.email) window.location.href = res.url;
                    if (res.data.mobile) SendMobile(res.data.mobile);
                    if (res.data.email) SendEmail(res.data.email);
                    window.location.href = res.url;
                }
            }
        });
    }

    // 发送短信
    function SendMobile(result) {
        if (result) {
            $.ajax({
                url: result.url,
                data: result.data,
                type:'post',
                dataType:'json'
            });
        }
    }

    // 发送邮件
    function SendEmail(result) {
        if (result) {
            $.ajax({
                url: result.url,
                data: result.data,
                type:'post',
                dataType:'json'
            });
        }
    }
</script>
